<template>
  <div class="page">
    <div class="item" v-for="(it,index) of dataList" :class="selectedIndex==index?'then':''" @click="selected(index,it)" :key="index">
      <div class="title">{{it.title}}</div>
      <i class="el-icon-close close" @click.stop="close(index,it)"></i>
    </div>
  </div>
</template>

<script>
import {mapState} from "vuex"
import {ipcRenderer} from "electron";
export default {
  name: "auHeader",
  data(){
    return {

    }
  },
  computed:{
    ...mapState({
      dataList: state => state.dataList,
      selectedIndex: state => state.selectedIndex
    })
  },
  methods:{
    close(index,it){
      this.$emit("on-close",index,it);
      //删除文件夹
      ipcRenderer.invoke("image-del",it.id);
      this.$store.commit('removeData',it.id);

      if(index==this.selectedIndex && this.selectedIndex!=0){
        this.$store.commit('setSelectIndex',0);
      }
    },
    selected(index,it){
      this.$store.commit('setSelectIndex',index);
      this.$emit("on-selected",index,it);
      console.log(this.dataList[this.selectedIndex])
    }
  },
  created() {
    this.selectedIndex=this.value;
  }
}
</script>

<style scoped lang="scss">
@import "../styles/public";
.page{
  height: 100%;
  display: flex;
  flex-flow: row nowrap;
  align-items: center;
  overflow-x: hidden;
  padding: 0 8px;
  font-size: 12px;
  @include scroll(2px);
}
.item{
  flex: 0;
  display: flex;
  flex-flow: row nowrap;
  height: 26px;
  align-items: center;
  padding: 0 8px;
  cursor: default;
  margin-right: 4px;
  background: #7795b3;
  &:hover{
    background: #637d97;
  }
  &.then{
    background: #1357a5!important;
    .title{

    }
  }

  .title{
    flex: 1;
    margin-right: 8px;
    color: #efefef;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .close{
    flex-shrink: 0;
    color: #B3C0D1;
    height: 12px;
    width: 12px;
    font-size: 10px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    &:hover{
      background: #B3C0D1;
      color: #6b8cad;
    }
  }
}
</style>
